package com.easygo.controller;

import com.easygo.common.ResultEnum;
import com.easygo.common.ResultResponse;
import com.easygo.common.TimeUtils;
import com.easygo.pojo.User;
import com.easygo.service.UserService;
import org.springframework.context.annotation.Scope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
@Scope("prototype")
public class UserController {

    @Resource
    UserService userService;


    @GetMapping("/user_list")
    public List<User> list(){
        return  userService.findUsers();
    }

    @GetMapping("/user_mybatislus_list")
    public List<User> list1(){
        return  userService.list(null);
    }


    /*
    * 注册功能 新增用户
    * */
    @PostMapping("/user_register")
    public ResultResponse userRegist(@RequestBody User user){
        user.setCreated(TimeUtils.getNow());
        user.setUpdated(TimeUtils.getNow());

        Boolean b = userService.save(user);
        if (b){
            return ResultResponse.success(ResultEnum.INSERT_SUCCESS);
        }
        return ResultResponse.success(ResultEnum.INSERT_SUCCESS);
    }
}
